package com.zenghus.v2.executor;

import com.zenghus.v2.mapper.MapperRegistory;
import com.zenghus.v2.result.ResultHandler;
import com.zenghus.v2.statement.StatementHandler;

import java.lang.reflect.InvocationTargetException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public class SimplExecutor implements Executor {


    public <T> T query(MapperRegistory.MapperDate mapperData, Object args) {
        PreparedStatement preparedStatement=new StatementHandler().query(mapperData.getSql(),args);
        try {
            return new ResultHandler().handle(preparedStatement,mapperData.getType());
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
}
